package tinyms.posture.hooks;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tinyms.posture.jobs.IndexPostureDataJob;
import tornadoj.points.IScheduler;

import java.util.Date;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;
import static org.quartz.DateBuilder.*;

/**
 *
 * Created by tinyms on 15/10/9.
 */
public class JobTask implements IScheduler{
    private static Logger Log = LoggerFactory.getLogger(JobTask.class);
    @Override
    public void doInScheduler(Scheduler scheduler) {
        Date startTime = nextGivenSecondDate(null, 10);
        JobDetail jobDetail = newJob(IndexPostureDataJob.class).withIdentity("job1", "IndexPostureDataJob").build();
        SimpleTrigger trigger = newTrigger()
                .withIdentity("trigger1", "IndexPostureDataJob")
                .startAt(startTime)
                .withSchedule(simpleSchedule().withIntervalInMinutes(30))
                .build();
        try {
            scheduler.scheduleJob(jobDetail, trigger);
        } catch (SchedulerException e) {
            Log.error(e.getLocalizedMessage());
        }
    }
}
